<?php

/*
 * This file is part of the prestaBreadcrumb package.
 * (c) Julien Fusco <jfusco@prestaconcept.net>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */


require_once(dirname(__FILE__).'/../../../../../test/bootstrap/unit.php');

$t = new lime_test(9, new lime_output_color());

// *************
// *** Test prestaBreadcrumb class
// *************

$oprestaBreadcrumb = prestaBreadcrumb::getInstance();

$t->diag('1 - prestaBreadcrumb::addItemsByArray()');

$items = array(
	array('text' => 'Article', 	'uri' => '@article'),
	array('text' => 'News', 	'uri' => 'uri'),
	array('text' => 'Blog', 	'uri' => 'blog'),
);
$t->isa_ok($oprestaBreadcrumb->addItemsByArray($items), prestaBreadcrumb, 'accept valid array and return a prestaBreadcrumb object');
$t->is( count($oprestaBreadcrumb->getItems()) - 1, count($items), 'add all given array as items'); // The -1 is for the root element

$oprestaBreadcrumb->clearItems();

try 
{
	$oprestaBreadcrumb->addItemsByArray(array());
	$t->pass('accept empty array as parameter');
}
catch( Exception $e)
{
	$t->fail('dont accept empty array as parameter');
}

try
{
	$items = '';
	$oprestaBreadcrumb->addItemsByArray($items);
	$t->fail('accept a non array parameter');
}
catch (sfException $e)
{
	$t->pass('throw an exception if the param is not an array');
}

$oprestaBreadcrumb->clearItems();
$t->diag('2 - prestaBreadcrumb::addItems()');

try
{
	$oprestaBreadcrumb->addItem('Article', '@article')
		->addItem('News', 'uri')
		->addItem('Blog', 'blog');
	$t->pass('accept some item add, using fluent method');
}
catch( Exception $e )
{
	$t->fail('dont accept some item add, using fluent method');
}

$t->is( count($oprestaBreadcrumb->getItems()), 4, 'add all given array as items'); // Dont forget the root element

$t->diag('4 - prestaBreadcrumb::clearItems()');
$oprestaBreadcrumb->clearItems();
$t->is( count($oprestaBreadcrumb->getItems()), 1, 'dont remove the root item');

$t->diag('3 - prestaBreadcrumb::setTemplate()');
$t->isa_ok($oprestaBreadcrumb->setTemplate('%s'), prestaBreadcrumb, 'accept valid string and return a prestaBreadcrumb object');

try
{
	$oprestaBreadcrumb->setTemplate(null);
	$t->fail('accept a null parameter as template');
}
catch (sfException $e)
{
	$t->pass('throw an exception if the param is null');
}

